/**
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 *         
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. Unless required by applicable law or
 * agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package org.rhok.ncn.background;

import org.rhok.ncn.common.CommonData;
import org.rhok.ncn.common.SignalCalculator;
import org.rhok.ncn.common.Utils;

import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.util.Log;

/**
 * Listener to track the phone's signal strength and update a text view with that information
 * as it changes.
 * @author pfritzsche
 *
 */
public class TrackingPhoneStateListener extends PhoneStateListener {
    /**
     * Called when the phone's signal strength has changed. Updates the context's signal text value
     * for use by the location listener when recording information and updates the text view
     * displaying that information to the user.
     */
    @Override public void onSignalStrengthsChanged(SignalStrength ss) {
        int level = SignalCalculator.getLevel(ss);

        Log.d("SS", String.format("Signal level: %d", level));
        CommonData.signalStrength = level;
        Utils.updateLocation(null);

        super.onSignalStrengthsChanged(ss);
    }

}
